#!/usr/bin/make -f

#export DH_VERBOSE=1

DEB_HOST_ARCH := $(shell dpkg-architecture -qDEB_HOST_ARCH)

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
    NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
    MAKEFLAGS += -j$(NUMJOBS)
endif


configure: configure-stamp
configure-stamp:
	dh_testdir

	./autogen.sh
	./configure $(CROSS) \
	    --prefix=/usr \
	    CFLAGS="$(CFLAGS)" \
	    LDFLAGS="-Wl,--as-needed -Wl,-z,defs" \

	touch configure-stamp

build: build-stamp

build-stamp: configure-stamp
	dh_testdir

	$(MAKE) $(MAKEFLAGS)

	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	if [ -e Makefile ]; then make distclean; fi
	rm -rf config.log

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	$(MAKE) DESTDIR=$(CURDIR)/debian/tmp install

binary-indep: build install

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_install
	dh_installchangelogs
	dh_installdocs
	dh_lintian
	dh_link
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure
